<template>
  <div class="parking-stats-panel">
    <div class="chart-container">
      <svg viewBox="0 0 100 100">
        <circle cx="50" cy="50" r="45" class="bg"></circle>
        <circle cx="50" cy="50" r="45" class="progress" :style="{ strokeDasharray: circumference }"></circle>
      </svg>
      <div class="percentage">{{ animatedRate }}%</div>
    </div>
    <div class="info">
      <div class="info-item">
        <span class="label">车位总数</span>
        <span class="value">{{ animatedTotal }}</span>
      </div>
      <div class="info-item">
        <span class="label">已占用</span>
        <span class="value occupied">{{ animatedOccupied }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { computed, defineProps } from 'vue';
import { useCountUp } from '@/composables/useCountUp';

const props = defineProps({
  stats: {
    type: Object,
    required: true,
    default: () => ({ total: 0, occupied: 0 }),
  },
});

const occupancyRate = computed(() => {
  if (!props.stats.total) return 0;
  return ((props.stats.occupied / props.stats.total) * 100);
});

const animatedTotal = useCountUp(() => props.stats.total || 0);
const animatedOccupied = useCountUp(() => props.stats.occupied || 0);
const animatedRate = useCountUp(() => occupancyRate.value);

const circumference = computed(() => {
  const radius = 45;
  const circum = 2 * Math.PI * radius;
  if (!props.stats.total) return `0 ${circum}`;
  const progress = (props.stats.occupied / props.stats.total) * circum;
  return `${progress} ${circum}`;
});
</script>

<style scoped>
.parking-stats-panel {
  display: flex;
  align-items: center;
  justify-content: space-around;
  height: 100%;
  padding: 0 20px;
}
.chart-container {
  position: relative;
  width: 120px;
  height: 120px;
}
.percentage {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 28px;
  font-weight: bold;
  color: #00e5ff;
}
svg {
  transform: rotate(-90deg);
}
circle {
  fill: none;
  stroke-width: 10;
}
.bg {
  stroke: rgba(255, 255, 255, 0.1);
}
.progress {
  stroke: #00e5ff;
  stroke-linecap: round;
  transition: stroke-dasharray 0.5s ease;
}
.info {
  display: flex;
  flex-direction: column;
  gap: 15px;
  font-size: 16px;
}
.info-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
.label {
  color: #aed4ff;
  margin-bottom: 5px;
}
.value {
  font-size: 22px;
  font-weight: bold;
  color: #fff;
}
.value.occupied {
    color: #fdd835;
}
</style> 